<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>万年历</title>
		<style>
			table{
				border-collapse: collapse;
			}
			td{
				text-align: right;
				padding: 10px;
			}
			td:hover{
				color: red;
				background: orange;
			}
		</style>
	</head>
	<body>
	</body>
	<script>
		function getMonthDayCount(year,month){
			var now=new Date();
			var y=year||now.getFullYear();
			var m=month||now.getMonth()+1;
			var dcount=31;
			if(m==4||m==6||m==9||m==11){
				dcount=30
			}else if(m==2){
				if(y%4==0&&y%100!=0||y%400==0){
					dcount=29;
				}else{
					dcount=28;
				}
			}
			return dcount;
		}
		var w=1;
		for(var t=2018;t<=2028;t++){
		document.write("<h2 style='clear:both'>"+t+"年</h2>");
		for(var k=1;k<=12;k++){
		document.write("<table border=\"1\" style='float:left;margin:10px'> ");
		document.write("<tr><td colspan='7'><h3>"+t+"年"+k+"月</h3></td></tr>");
		document.write("<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td>")
		for(var i=1;i<=6;i++){
			document.write("<tr>");
			for(var j=1;j<=7;j++){
			document.write("<td>");
			var d=j+(i-1)*7-(w==0?7:w);
			if(d<1){
				if(k-1<=0){
					d+=getMonthDayCount(t-1,12);
				}else{
					d+=getMonthDayCount(t,k-1);
				}
			}else if(d>getMonthDayCount(t,k)){
				d-=getMonthDayCount(t,k);
			}
			document.write(d)
			document.write("</td>");
			}
			document.write("</tr>");
		}
		document.write("</table>");
		w=getMonthDayCount(t,k)%7+w%7;
		if(w>=7) w=w-7;
		console.log(w)
		}
		}
	</script>
</html>
